home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / boot / AllocP.lha / AllocP / AllocP.c next >
Encoding:
C/C++ Source or Header  |  1997-08-01  |  5.7 KB  |  187 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *  AllocP - supply a better AllocMem/AllocVec                          *
  4.  *                                                                      *
  5.  *  written by Andreas R. Kleinert                                      *
  6.  *  Andreas_Kleinert@t-online.de                                        *
  7.  *                                                                      *
  8.  *  No Assembler - 100 percent C                                        *
  9.  *                                                                      *
  10.  * V1.0 :                                                               *
  11.  *        - first release                                               *
  12.  *                                                                      *
  13.  ************************************************************************/
  14.  
  15. #define __USE_SYSBASE
  16.  
  17. #include <exec/execbase.h>
  18. #include <exec/memory.h>
  19. #include <intuition/intuitionbase.h>
  20. #include <libraries/gadtools.h>
  21.  
  22. #include <string.h>
  23. #include <stdio.h>
  24.  
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/intuition.h>
  28. #include <proto/utility.h>
  29.  
  30. #define N (NULL)
  31.  
  32.  
  33. extern struct ExecBase *SysBase;
  34.  
  35. struct IntuitionBase *IntuitionBase = N;
  36.  
  37.  
  38. APTR __far NewAllocMemVec;
  39. ULONG __far __asm (*OrigAllocMemVec)(register __d0 ULONG size,
  40.                                      register __d1 ULONG memf,
  41.                                      register __a6 struct ExecBase *ExecBase_a6);
  42.  
  43. APTR __far NewAllocVecVec;
  44. ULONG __far __asm (*OrigAllocVecVec)(register __d0 ULONG size,
  45.                                      register __d1 ULONG memf,
  46.                                      register __a6 struct ExecBase *ExecBase_a6);
  47.  
  48.  
  49. ULONG __asm NewAllocMem(register __d0 ULONG size,
  50.                         register __d1 ULONG memf,
  51.                         register __a6 struct ExecBase *ExecBase_a6)
  52. {
  53.  ULONG ptr;
  54.  
  55.  ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
  56.  if(!ptr)
  57.   {
  58.    OrigAllocMemVec(0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
  59.  
  60.    ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
  61.   }
  62.  
  63.  return((ULONG) ptr);
  64. }
  65.  
  66. ULONG __asm NewAllocVec(register __d0 ULONG size,
  67.                         register __d1 ULONG memf,
  68.                         register __a6 struct ExecBase *ExecBase_a6)
  69. {
  70.  ULONG ptr, nsize;
  71.  
  72.  
  73.  nsize = size + (size & 3); /* avoid alignment gaps */
  74.  
  75.  ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
  76.  if(!ptr)
  77.   {
  78.    OrigAllocVecVec(0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
  79.  
  80.    ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
  81.   }
  82.  
  83.  return((ULONG) ptr);
  84. }
  85.  
  86. /* *************************************************** */
  87. /* *                                                 * */
  88. /* * Compiler Stuff for BackgroundIO                 * */
  89. /* *                                                 * */
  90. /* *************************************************** */
  91.  
  92. long  __stack        = 8192;
  93. char *__procname     = "AllocP";
  94. long  __priority     = 1;
  95. long  __BackGroundIO = 1;           /* TRUE : We DO BackGroundIO !     */
  96.  
  97. extern BPTR _Backstdout;            /* NULL, if started from Workbench */
  98.  
  99. void __regargs __chkabort(void) { }
  100. void __regargs _CXBRK(void)     { }
  101.  
  102. char vertext [] = "\0$VER: AllocP V1.0";
  103.  
  104.  
  105. typedef unsigned long (*FUNCCAST)();
  106.  
  107. long main(long argc, char **argv)
  108. {
  109.  long retval = 0;
  110.  
  111.  APTR task;
  112.  
  113.  Forbid();
  114.  task = FindTask(N);
  115.  Permit();
  116.  
  117.  if(task) SetTaskPri(task, __priority);
  118.  
  119.  
  120.  IntuitionBase = (APTR) OpenLibrary("intuition.library", 39);
  121.  if(IntuitionBase)
  122.   {
  123.    UtilityBase = (APTR) OpenLibrary("utility.library", 37);
  124.    if(UtilityBase)
  125.     {
  126.      OrigAllocMemVec = (long (* __asm )(register __d0 ULONG size,
  127.                                         register __d1 ULONG memf,
  128.                                         register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0xc6, (APTR)NewAllocMem);
  129.  
  130.      OrigAllocVecVec = (long (* __asm )(register __d0 ULONG size,
  131.                                         register __d1 ULONG memf,
  132.                                         register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0x2ac, (APTR)NewAllocVec);
  133.  
  134.      if(OrigAllocMemVec || OrigAllocVecVec)
  135.       {
  136.        if(task) SetTaskPri(task, -10);
  137.        Wait(SIGBREAKF_CTRL_C);
  138.        if(task) SetTaskPri(task, 1);
  139.  
  140.        NewAllocMemVec= (APTR) SetFunction((APTR)SysBase, -0xc6,  (APTR)OrigAllocMemVec);
  141.        NewAllocVecVec= (APTR) SetFunction((APTR)SysBase, -0x2ac, (APTR)OrigAllocVecVec);
  142.  
  143.        if(NewAllocMemVec!=NewAllocMem)
  144.         {
  145.          ULONG idcmp = N;
  146.          struct EasyStruct estr;
  147.  
  148.          estr.es_StructSize   = sizeof(struct EasyStruct);
  149.          estr.es_Flags        = N;
  150.          estr.es_Title        = "AllocP Request";
  151.          estr.es_TextFormat   = "Error while removing from system !\n"
  152.                                 "There were more patches !"
  153.                                 "Do a reset soon !";
  154.          estr.es_GadgetFormat = "Ok";
  155.  
  156.          EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
  157.         }
  158.  
  159.        if(NewAllocVecVec!=NewAllocVec)
  160.         {
  161.          ULONG idcmp = N;
  162.          struct EasyStruct estr;
  163.  
  164.          estr.es_StructSize   = sizeof(struct EasyStruct);
  165.          estr.es_Flags        = N;
  166.          estr.es_Title        = "AllocP Request";
  167.          estr.es_TextFormat   = "Error while removing from system !\n"
  168.                                 "There were more patches !"
  169.                                 "Do a reset soon !";
  170.          estr.es_GadgetFormat = "Ok";
  171.  
  172.          EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
  173.         }
  174.  
  175.       }else retval = 20;
  176.  
  177.      CloseLibrary((struct Library *) UtilityBase);
  178.  
  179.     }else retval = 20;
  180.  
  181.    CloseLibrary((struct Library *) IntuitionBase);
  182.  
  183.   }else retval = 20;
  184.  
  185.  return(retval);
  186. }
  187.